<?php
// $Id: views_handler_area_text.inc,v 1.1.2.1 2010/01/19 22:11:27 merlinofchaos Exp $

class views_handler_area_text extends views_handler_area {

  function option_definition() {
    $options = parent::option_definition();
    $options['content'] = array('default' => '', 'translatable' => TRUE);
    $options['format'] = array('default' => variable_get('filter_default_format', 1));
    return $options;
  }

  function options_form(&$form, &$form_state) {
    parent::options_form($form, $form_state);

    $form['content'] = array(
      '#type' => 'textarea',
      '#default_value' => $this->options['content'],
      '#rows' => 6,
      '#description' => $description,
    );

    $form['format'] = filter_form($this->options['format']);
  }

  function options_submit(&$form, &$form_state) {
    $form_state['values']['options']['format'] = $form_state['values']['format'];
    parent::options_submit($form, $form_state);
  }

  function render($empty = FALSE) {
    if (!$empty || !empty($this->options['empty'])) {
      return $this->render_textarea($this->options['content'], $this->options['format']);
    }
    return '';
  }

  /**
   * Render a text area, using the proper format.
   */
  function render_textarea($value, $format) {
    static $formats = array();

    // Check to make sure the filter format exists; if not, we don't
    // display anything.
    $format = filter_resolve_format($format);

    if (!array_key_exists($format, $formats)) {
      $formats[$format] = db_result(db_query("SELECT name FROM {filter_formats} WHERE format = %d", $format));
    }

    if (!$formats[$format]) {
      return;
    }

    if ($value) {
      return check_markup($value, $format, FALSE);
    }
  }
}
